package com.bytedance.scenedemo.ability_compatibility.window;

import com.bytedance.scene.Scene;
import com.bytedance.scene.ktx.SceneExtensions;
import com.bytedance.scenedemo.ResourceTable;
import com.bytedance.scenedemo.utility.ColorUtil;
import ohos.aafwk.content.Intent;
import ohos.agp.components.*;
import ohos.agp.utils.Color;

/**
 * @author JiangQi
 * @since 2018-08-21
 */
public class WindowLayoutDemo extends Scene implements Component.ClickedListener {

    private Component parse;

    @Override
    public Component onCreateView(LayoutScatter scatter, ComponentContainer container, Intent intent) {
        parse = scatter.parse(ResourceTable.Layout_basic_layout, container, false);
        return parse;
    }

    @Override
    public void onAbilityCreated(Intent intent) {
        super.onAbilityCreated(intent);
        requireAbility().getWindow().setStatusBarColor(Color.getIntColor("#aed581"));
        requireAbility().getWindow().setNavigationBarColor(Color.getIntColor("#4db6ac"));
        this.getView().setBackground(ColorUtil.getMaterialColor(1));
        Text name = (Text) parse.findComponentById(ResourceTable.Id_name);
        name.setText(SceneExtensions.getNavigationScene(this).getStackHistory());
        Button btn = (Button) parse.findComponentById(ResourceTable.Id_btn);
        btn.setText("扩展布局到状态栏和导航栏下");
        btn.setClickedListener(this);
        Button btn2 = (Button) parse.findComponentById(ResourceTable.Id_btn2);
        btn2.setText("切换显示隐藏状态栏和导航栏");
        btn2.setVisibility(Component.VISIBLE);
        btn2.setClickedListener(this);
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()) {
            case ResourceTable.Id_btn:
                requireAbility().getWindow().setStatusBarVisibility(Component.VISIBLE);
                break;
            case ResourceTable.Id_btn2:
                requireAbility().getWindow().setStatusBarVisibility(Component.HIDE);
                break;
            default:
                break;
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        requireAbility().getWindow().setStatusBarColor(Color.getIntColor("#F36D60"));
        requireAbility().getWindow().setNavigationBarColor(Color.getIntColor("#FEFEFE"));
    }
}
